<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="js/vue.js"></script>
		<style type="text/css">
			.message{
				display: inline-block;
				width:160px;
			}
			
			.success{
				background-color: lightgreen;
			}
			
			.msg-fail{
				background-color: pink;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<span>电话号码：{{cellPhone}}</span>
			<span class="message" :class="[successClass,failClass]">{{msg}}</span>
		</div>
		
		<script type="text/javascript">
		const msgSuccess = "手机号码格式正确"
		const msgFail="手机号码格式错误！"
			var vm = new Vue({
				el:"#app",
				data:{
					cellPhone:"13968290221",
					msg:msgSuccess,
					
					successClass:"success",
					failClass:"",
				},
				computed:{
					isOk(){
						var reg = /^1[3-9]\d{9}$/;
						return reg.test(this.cellPhone);
					}
				},
				
				watch:{
					cellPhone(){
						if(this.isOk){
							this.successClass = "success";
							this.failClass = "";
							this.msg = msgSuccess;
						}else{
							this.successClass = "";
							this.failClass = "msg-fail";
							this.msg = msgFail;
						}
					}
				}
			})
		</script>
	</body>
</html>
